package com.autumn.scheduler.job;

import java.util.Map;
import java.util.UUID;

import com.autumn.scheduler.api.constant.ApiConstants;

/**
 * 作业执行信息
 * 
 * @author 老码农
 *
 *         2018-03-19 15:52:37
 */
public class JobExecutionInfo {
	private final long executeNumbers;
	private final String jobFriendlyName;
	private final String queueName;
	/**
	 * {@link JobConstants.ExecuteOperation}
	 */
	private final int executeOperation;
	private final long runNumbers;
	private final Map<String, Object> parameterMap;
	private final String jobExecuteId;

	/**
	 * 
	 * @param jobFriendlyName
	 * @param queueName
	 * @param executeNumbers
	 * @param executeOperation
	 * @param runNumbers
	 * @param parameterMap
	 */
	public JobExecutionInfo(String jobFriendlyName, String queueName, long executeNumbers, int executeOperation,
			long runNumbers, Map<String, Object> parameterMap) {
		super();
		this.jobFriendlyName = jobFriendlyName;
		this.queueName = queueName;
		this.executeNumbers = executeNumbers;
		this.executeOperation = executeOperation;
		this.runNumbers = runNumbers;
		this.parameterMap = parameterMap;
		this.jobExecuteId = UUID.randomUUID().toString().replace("-", "");
	}

	/**
	 * 获取任务的友好名称
	 * 
	 * @return
	 */
	public String getJobFriendlyName() {
		return jobFriendlyName;
	}

	/**
	 * 获取队列名称
	 * 
	 * @return
	 *
	 */
	public String getQueueName() {
		return queueName;
	}

	/**
	 * 执行指定次数后不再执行,<0表示不限
	 * 
	 * @return
	 *
	 */
	public long getExecuteNumbers() {
		return executeNumbers;
	}

	/**
	 * 执行后操作
	 * <p>
	 * {@link com.autumn.scheduler.api.constant.core.JobConstants.ExecuteOperation}
	 * </p>
	 * 
	 * @return
	 *
	 */
	public int getExecuteOperation() {
		return executeOperation;
	}

	/**
	 * 获取运行次数
	 * 
	 * @return
	 *
	 */
	public long getRunNumbers() {
		return runNumbers;
	}

	/**
	 * 获取参数
	 * 
	 * @return
	 *
	 */
	public Map<String, Object> getParameterMap() {
		return parameterMap;
	}

	/**
	 * 获取是否删除
	 * 
	 * @return
	 *
	 */
	public boolean isDeleteJob() {
		if (this.executeNumbers > 0 && this.runNumbers >= this.executeNumbers) {
			return this.executeOperation == ApiConstants.ExecuteOperation.DELETE;
		} else {
			return false;
		}
	}

	/**
	 * 获取是否暂停
	 * 
	 * @return
	 *
	 */
	public boolean isPauseJob() {
		if (this.executeNumbers > 0 && this.runNumbers >= this.executeNumbers) {
			return this.executeOperation == ApiConstants.ExecuteOperation.PAUSE;
		} else {
			return false;
		}
	}

	/**
	 * 获取作业执行Id
	 * 
	 * @return
	 */
	public String getJobExecuteId() {
		return jobExecuteId;
	}

}
